<!--
 * @Author: 雷宇航
 * @Date: 2021-07-19 14:57:07
 * @LastEditTime: 2021-08-03 10:49:36
 * @LastEditors: 雷宇航
 * @Description: 
 * @FilePath: \icm-vue\src\views\hifar\contract\modules\ReturnMoneyManagementForm.vue
-->
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractNum']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="合同名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractName']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['customerName']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="合同金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractMoney']" disabled>
                <span slot="addonAfter">元</span>
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="销售经理" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['salesman']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="售前经理" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['preSaleLeader']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="项目经理" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectManager']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="回款条件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['returnCondition_dictText']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="计划回款金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['expectMoney']" disabled>
                <span slot="addonAfter">元</span>
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="实际回款金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['actualMoney']" disabled>
                <span slot="addonAfter">元</span>
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="实际回款时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date
                v-decorator="['actualTime']"
                :trigger-change="true"
                style="width: 100%"
                disabled
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="是否开票" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['billing']" disabled></j-switch>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="开票比例" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['billingRatio']" disabled></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="计划回款时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date
                placeholder="请选择计划回款时间"
                v-decorator="['expectTime', validatorRules.expectTime]"
                :trigger-change="true"
                style="width: 100%"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="回款负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-user-by-dep :multi="false"
                v-decorator="['paymantCharger', validatorRules.paymantCharger]"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>
import pick from 'lodash.pick'
import { httpAction } from '@/api/manage'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
export default {
  name: 'ReturnMoneyManagemenForm',
  mixins: [JEditableTableMixin],
  components: {},
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 2 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 22 },
      },
      validatorRules: {
        paymantCharger: {
          initialValue:"",
          rules: [{ required: true, message: '请选择回款负责人!' }],
        },
        expectTime: {
          rules: [{ required: true, message: '请选择计划回款时间!' }],
        },
      },
      url: {
        add: '/contract/contractSalePaymentCollection/add',
        edit: '/contract/contractSalePaymentCollection/edit',
        queryById: '/contract/contractSalePaymentCollection/queryById'
      },
      fields: [
        'contractNum',
        'contractName',
        'customerName',
        'contractMoney',
        'salesman',
        'preSaleLeader',
        'projectManager',
        'returnCondition_dictText',
        'expectMoney',
        'expectTime',
        'paymantCharger',
        'actualMoney',
        'actualTime',
        'billing',
        'billingRatio',
      ],
    }
  },
  props: {
    //流程表单data
    formData: {
      type: Object,
      default: () => {},
      required: false,
    },
    //表单模式：false流程表单 true普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false,
    },
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    },
    showFlowSubmitButton() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return true
        }
      }
      return false
    },
  },
  created() {
    //如果是流程中表单，则需要加载流程表单data
    this.showFlowData()
  },
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, this.fields))
      })
    },
    //渲染流程表单数据
    showFlowData() {
      if (this.formBpm === true) {
        let params = { id: this.formData.dataId }
        getAction(this.url.queryById, params).then((res) => {
          if (res.success) {
            this.edit(res.result)
          }
        })
      }
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          console.log('表单提交数据', formData)
          httpAction(httpurl, formData, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
  },
}
</script>

<style scoped>
</style>
